package com.yc.library.servlet;

import com.yc.library.bean.Book;
import com.yc.library.dao.BookDao;
import com.yc.library.mapper.BookMapper;
import com.yc.library.util.MyBatisHelper;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@WebServlet("/GetBookServlet.do/*")
public class GetBookServlet extends BaseServlet{
    private BookDao bdao = new BookDao();

    protected void GetBook(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("id");
//        Map<String,Object> list = bdao.getBook(id);
        SqlSession session = MyBatisHelper.getsSession();
        BookMapper mapper = session.getMapper(BookMapper.class);
        Book list = mapper.selectById(id);
        if( list == null ) { // 查无数据
            this.send(response, 500, null);
            return;
        }
        this.send(response, 200, list);
        session.close();
    }
}
